package com.xhh.enjoyapp.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.xhh.enjoyapp.Bean.User;
import com.xhh.enjoyapp.R;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;

/**
 * @description 我的信息
 * @author: weiXhh
 * @create: 2020-05-15 15:04
 **/
public class MyInfo extends AppCompatActivity {

    private ImageView back;
    private TextView myInfoName;
    private TextView myInfoPushInvitation;
    private TextView myInfoPushCommunity;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myinfo);

        initView();

        back.setOnClickListener(click->{
            finish();
        });

        // 获取信息
        getInfo();
    }

    private void getInfo() {
        User user = BmobUser.getCurrentUser(User.class);
        String id = user.getObjectId();
        BmobQuery<User> bmobQuery = new BmobQuery<>();
        bmobQuery.getObject(id, new QueryListener<User>() {
            @Override
            public void done(User user, BmobException e) {
                if(e == null){
                    myInfoName.setText(user.getUsername());
                } else {
                    Toast.makeText(MyInfo.this, "加载失败", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private void initView() {
        back = findViewById(R.id.mine_info_black);
        myInfoName = findViewById(R.id.mine_info_name);
        myInfoPushInvitation = findViewById(R.id.mine_info_invitation_num);
        myInfoPushCommunity = findViewById(R.id.mine_info_community_num);
    }
}
